package com.my.zidingyikongjian.view.six;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * 项目名称：贝塞尔曲线
 * 创建人：mwb
 * 创建时间：2018/7/23 9:10
 */

public class DrawBezier extends View {
    private Context context;

    public DrawBezier(Context context) {
        super(context);
    }

    public DrawBezier(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Paint paint = new Paint();
        paint.setStyle(Paint.Style.STROKE);
        paint.setColor(Color.GREEN);
        paint.setStrokeWidth(2);

        Path path = new Path();
//        path.moveTo(100, 300);
//        path.quadTo(200, 200, 300, 300);
//        path.quadTo(400, 400, 500, 300);

        // 画线
        path.moveTo(300, 300);
        path.lineTo(400, 200);
        canvas.drawPath(path, paint);

        path.moveTo(400, 200);
        path.lineTo(600, 400);
        canvas.drawPath(path, paint);

        path.moveTo(600, 400);
        path.lineTo(900, 300);
        canvas.drawPath(path, paint);

        Paint paint2 = new Paint();
        paint2.setStyle(Paint.Style.STROKE);
        paint2.setColor(Color.RED);
        paint2.setStrokeWidth(2);

        Path path2 = new Path();

        // 画曲线
        path2.moveTo(300, 300);
        path2.quadTo(300, 300, 350, 250);
        canvas.drawPath(path2, paint2);


        path2.quadTo(400, 200, 500, 300);
        canvas.drawPath(path2, paint2);

        path2.quadTo(600, 400, 750, 350);
        canvas.drawPath(path2, paint2);
    }
}
